import React, {useReducer} from 'react';
import userReducer, {initState, actions} from '../store/user'

const UseReducer = () => {
  // useReducer(userReducer, initState) 返回了store中的state以及reducer
  const [state, dispatch] = useReducer(userReducer, initState);
  return (
    <div>
      <p>useReducer的作用就是可以允许在函数组件中使用reducer相关的功能</p>
      <p>age: {state.info.age}</p>
      <p>name: {state.info.name}</p>
      <hr />
      <button onClick={()=>{dispatch(actions.changeAge(60))}}>退休</button>
    </div>
  );
}

export default UseReducer;
